namespace DotNetNuke.UI.WebControls
{
    using System;
    using System.Collections;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    internal class DNNTreeWriter : WebControl, IDNNTreeWriter
    {
        private DnnTree _tree;

        protected override void RenderChildren(HtmlTextWriter writer)
        {
            IEnumerator enumerator=null;
            try
            {
                enumerator = this._tree.TreeNodes.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    ((TreeNode) enumerator.Current).Render(writer);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    ((IDisposable) enumerator).Dispose();
                }
            }
        }

        protected override void RenderContents(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "DNNTree");
            writer.AddAttribute(HtmlTextWriterAttribute.Name, this._tree.UniqueID);
            writer.AddAttribute(HtmlTextWriterAttribute.Id, this._tree.UniqueID.Replace(":", "_"));
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            this.RenderChildren(writer);
            writer.RenderEndTag();
        }

        public void RenderTree(HtmlTextWriter writer, DnnTree tree)
        {
            this._tree = tree;
            this.RenderControl(writer);
        }
    }
}

